<template>
	<div class="cardScrollContent">
		<div class="cardScrollBox">
			<div class="cardScrollBoxContent">
				<div class="cardScrollBoxContentItem" v-for="(item, index) in listData" :key="index" :class="{ 'animate-up': animateUp }">
					<i :class="item.iconClass"></i>
					<p>{{ "[" + item.type + "]" + item.text }}</p>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
export default {
	name: "CardScroll2",
	props: {
		list: {
			type: Array,
			default: () => [],
		},
	},
	data() {
		return {
			animateUp: false, // 是否开启滚动
			timer: null, // 定时器
			listData: this.list,
		};
	},
	created() {},
	mounted() {
		this.timer = setInterval(this.scrollAnimate, 1500);
	},
	destroyed() {
		clearInterval(this.timer);
	},
	methods: {
		// 定时器开启滚动播报
		scrollAnimate() {
			this.animateUp = true;
			setTimeout(() => {
				this.listData.push(this.listData[0]);
				this.listData.shift();
				this.animateUp = false;
			}, 500);
		},
	},
};
</script>
<style lang="less" scoped>
.cardScrollContent {
	width: 100%;
	height: 100%;
	box-sizing: border-box;
	padding: 0 12px;
	background: transparent;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: center;
	.cardScrollBox {
		width: 100%;
		height: 100%;
		overflow: hidden;
		.cardScrollBoxContent {
			width: 108%;
			height: 100%;
			overflow-y: scroll;
			.animate-up {
				transition: all 0.5s ease-in-out;
				transform: translateY(-40px);
			}
			.cardScrollBoxContentItem {
				width: 100%;
				height: 20%;
				display: flex;
				flex-direction: row;
				justify-content: flex-start;
				align-items: center;
				/deep/ [class*="wj-icon"] {
					color: #f2a16e;
					font-size: 18px;
					margin: 6px 8px;
				}
				p {
					/*多减18px（因为108%的宽度隐藏滚动条）*/
					width: calc(100% - 18px - 16px - 18px);
					padding: 0;
					margin: 0;
					font-size: 16px;
					color: #f9f9f9;
					line-height: 18px;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}
		}
	}
}
</style>
